home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / GCVT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  730 b   |  23 lines

  1. /* gcvt.c, from pp.176-177 of Turbo C Bible  */
  2. /* Converts a double-precision floating-point value into a string
  3.     using a    specified number of significant digits
  4.     and having an embedded decimal point. */
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <stdlib.h>
  8. main(int argc, char **argv)
  9. {
  10.     int significant_digits = 6;
  11.     double value;
  12.     char  buffer[80];            /* Buffer for gcvt                  */
  13.     if(argc < 2)
  14.     {
  15.         printf("Usage: %s <value>\n", argv[0]);
  16.     }
  17.     else
  18.     {                              /* Convert the number to internal   */
  19.         value = atof(argv[1]); /*     form.  Then call gcvt.       */
  20.         gcvt(value, significant_digits, buffer);
  21.         printf("Buffer from gcvt contains: %s\n", buffer);
  22.     }
  23. }